package org.jaychan.live.api.controller;


import org.apache.dubbo.config.annotation.DubboReference;
import org.jaychan.live.user.dto.UserDTO;
import org.jaychan.live.user.interfaces.IUserRpc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("/user")
//@Slf4j
public class UserController {


    private static Logger logger = LoggerFactory.getLogger(UserController.class);


    @DubboReference
    private IUserRpc userRpc;


    @GetMapping("/getUserInfo")
    public UserDTO getUserInfo(Long userId) {
        UserDTO userDTO = userRpc.getByUserid(userId);
        logger.info("userDto is :{}",userDTO);
        return userDTO;
    }

    @GetMapping("/updateUserInfo")
    public boolean updateUserInfo(Long userId,String nickname) {
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userId);
        userDTO.setNickName(nickname);
        return userRpc.updateUserInfo(userDTO);
    }

    @GetMapping("/insertOne")
    public boolean insertOne(Long userId) {
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userId);
        userDTO.setNickName("jay-test");
        userDTO.setSex(1);

        return userRpc.insertOne(userDTO);
    }


    @GetMapping("/batchQueryUserInfo")
    public Map<Long,UserDTO> batchQueryUserInfo(String userIdStr) {

        return userRpc.batchQueryUserInfo(Arrays.asList(userIdStr.split(",")).stream().map(Long::valueOf).toList());
    }


}


